package com.banana.manager.forest.service.impl.chemical;

import com.banana.manager.forest.dao.chemical.IDeviceDao;
import com.banana.manager.forest.entity.chemical.DeviceBean;
import com.banana.manager.forest.service.iidevice.IDeviceService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class DeviceServiceImpl implements IDeviceService {

    @Resource
    private IDeviceDao deviceDao;

    @Override
    public DeviceBean addDevice(DeviceBean deviceBean) {
        deviceDao.insert(deviceBean);
        return deviceDao.selectById(deviceBean.getDeviceId());
    }

    @Override
    public PageInfo<DeviceBean> findBlurPage(Integer page, String deviceName, String deviceMeasure, String deviceType) {
        String deviceNameNew = "%"+deviceName+"%";
        String deviceMeasureNew = "%"+deviceMeasure+"%";
        String deviceTypeNew = "%"+deviceType+"%";

        QueryWrapper<DeviceBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("device_name",deviceNameNew);
        queryWrapper.like("device_measure",deviceMeasureNew);
        queryWrapper.like("device_type",deviceTypeNew);
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(deviceDao.selectList(queryWrapper));
    }

    public DeviceBean findById(Integer id){
        return deviceDao.selectById(id);
    }
}
